import 'package:flutter_member_v3/network/common/net_manager.dart';
import 'package:flutter_member_v3/network/index/net_index_path.dart';
import 'package:dio/dio.dart';

class CNWIndexNetManager {
  // 首页banner 图的接口实现
  static Future<List> bannerList({int type, int pageShow}) async {
    Map<String, dynamic> queryParameters = {};
    if (type != null) queryParameters['type'] = type;
    if (pageShow != null) queryParameters['page_show'] = pageShow;

    List list = await CNWNetManager.get<List>(
      net_index_path_bannerlist,
      queryParameters: queryParameters,
    );
    return list;
  }

  // 首页模块列表接口实现
  static Future<List> moduleList() async {
    List list = await CNWNetManager.get<List>(
      net_index_path_modulelist,
    );
    return list;
  }

  // 首页 模块详情列表接口实现
  static Future<List> componentList(int moduleId, int type) async {
    if (moduleId == null || type == null) {
      Response response = Response(statusCode: 404, data: {
        "errorCode": '-1',
        "errorMsg": 'moudleId or type can not be null.'
      });
      return response.data;
    }

    Map<String, dynamic> queryParameters = {
      'module_id': moduleId ?? '',
      'module_type': type ?? ''
    };

    List list = await CNWNetManager.get<List>(
      net_index_path_componentlist,
      queryParameters: queryParameters,
    );
    return list;
  }

  // 课程列表接口实现
  static Future<Map> courseList({
    int courseType = -1,
    String code = 'all',
    int difficulty = -1,
    int isFree = -1,
    int q = -1,
    int page = 1,
    int size = 20, 
  }) async {
    Map<String, dynamic> queryParameters = {};
    if (courseType != null) queryParameters['course_type'] = courseType;
    if (code != null) queryParameters['code'] = code;
    if (difficulty != null) queryParameters['difficulty'] = difficulty;
    if (isFree != null) queryParameters['is_free'] = isFree;
    if (q != null) queryParameters['q'] = q;
    if (page != null) queryParameters['page'] = page;
    if (size != null) queryParameters['size'] = size;

    Map map = await CNWNetManager.get<Map>(
      net_index_path_courselist,
      queryParameters: queryParameters,
    );
    return map;
  }
}
